<?php

	include_once("bin/connexion.php");
	
	if(isset($_SESSION["user_id"]))
	{
		$id = $_SESSION["user_id"];
		$query = "SELECT * FROM user where id='$id'";
		$result = mysqli_query($bdd,$query);
		$user = mysqli_fetch_array($result);
		$num_biens = 0;
		
		if($user["bailleur"] == 1)
		{
			$query = "SELECT * FROM bien where id_owner='$id'";
			$result = mysqli_query($bdd,$query);
			$num_biens = mysqli_num_rows($result);
		}
		
		$infos = array($user["nom"], $user["prenom"], $user["bailleur"], $user["pic"], $num_biens, $user["mail"], $user["password"]);
	}
	else
	{
		header("location: freebed-login.php");
	}

	if(isset($_GET["id"]))
	{
		$id_bien = $_GET["id"];
		$query = "SELECT * FROM bien where id='$id_bien'";
		$ret_biens = mysqli_query($bdd,$query);
		
		$data = mysqli_fetch_array($ret_biens);
	
		//ville query
		$id_ville = $data['id_ville'];
		$ville = mysqli_fetch_array(mysqli_query($bdd, "SELECT * FROM ville WHERE id='$id_ville'"));
		
		//Image query
		$image = mysqli_fetch_array(mysqli_query($bdd, "SELECT path FROM photos WHERE id_bien='$data[0]'"))[0];
	}
	
	if (isset($_POST["envoyer"]))
	{
		$adresse = $_POST["adresse"];
		$ville = $_POST["ville"];
		$cp = $_POST["cp"];
		$prix1 = $_POST["prix1"];
		$prix2 = $_POST["prix2"];
		$online = $_POST["online"];
		$description = $_POST["description"];
		
		mysqli_query($bdd, "UPDATE bien 

		

	include_once("freebed-detail.html");

?>